// pages/user/report.js
const config = require('../../config')
const util = require('../../utils/util')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
    data: {
        items: [
            { name: '1', value: '淫秽色情' },
            { name: '2', value: '违法信息' },
            { name: '3', value: '垃圾营销' },
            { name: '4', value: '有害信息' },
            { name: '5', value: '人身攻击我' },
            { name: '6', value: '其他原因' },
        ], 
        input: false,
        types:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        this.setData({
            wid: e.wid,
            username: e.username
        })
    },
    //保存formid
    saveform: function (e) {
        var formid = e.detail.formId
        app.saveformid(formid)
    },
    //修改举报选项
    radioChange: function (e) {
        var types = e.detail.value
        this.setData({
            types: e.detail.value
        })
    },
    //输入举报内容
    reportinput: function (e) {
        var types = e.detail.value
        this.setData({
            input: e.detail.value
        })
    },
    report: function () {
        var that = this,
            input = that.data.input,
            types = that.data.types,
            wid = that.data.wid
        if (!types){
            wx.showModal({
                title: '失败',
                content: '请选择举报类型',
                showCancel: false
            })
        } else if (types == 6 && !input) {
            wx.showModal({
                title: '失败',
                content: '请填写举报说明',
                showCancel: false
            })
        }else{
            var headerkey = util.createheaderkey()
            wx.request({
                url: config.host + '/api/report/reportinfo',
                method: 'POST',
                header: {
                    'content-type': 'application/json',
                    'key': headerkey.key,
                    'time': headerkey.timestamp
                },
                data: {
                    'uid': app.globalData.uid,
                    'wid': wid,
                    'content': input,
                    'type': types
                },
                success: function (res) {
                    if (res.data.code == 200) {
                        wx.showModal({
                            title: '举报成功',
                            content: '举报成功，若该祝福存在违法违规情况，我们将严肃处理。感谢您的支持！',
                            showCancel: false,
                            success: function (res) {
                                wx.navigateBack()
                            }
                        })
                    }else{
                        wx.showModal({
                            title: '失败',
                            content: res.data.msg,
                            showCancel: false
                        })
                    }
                },
                fail: function (res) {
                    wx.showToast({
                        title: '提交举报失败!',
                        duration: 3000
                    })
                }
            })
        }
        
    },
  
})